package server;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;

public class ChattingServer {
	
    private final int port = 8888;
    
    public void startServer() {
     
        EventLoopGroup bossGroup=new NioEventLoopGroup();
        
        EventLoopGroup workerGroup=new NioEventLoopGroup();
        
        try {
        	
            ServerBootstrap bootstrap=new ServerBootstrap();
            
           
            bootstrap.group(bossGroup, workerGroup)
            	
            		
                    .channel(NioServerSocketChannel.class) 
                    
                    .option(ChannelOption.SO_BACKLOG, 1024)
                  
            
                    .option(ChannelOption.SO_KEEPALIVE, true)
                  
                    .childHandler(new ChattingServerInitializer());
           
            ChannelFuture channelFuture = bootstrap.bind(port).sync();
            System.out.println("Server Starting");
          
            channelFuture.channel().closeFuture().sync();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } finally {
        
            bossGroup.shutdownGracefully();
            workerGroup.shutdownGracefully();
        }
    }
}
